package com.homework;

import java.util.Scanner;

/**
 * 描述: 饮料简单工厂设计模式
 *
 * @author CodeYang
 * @version 2020/12/17 10:29
 */
public class DrinkSimplyFactory {
    /**
     * 获得Drnk对象
     * @param i
     * @return
     */
    public static Drink getDrinkInfo(int i) {
        String name = "";

        switch (i) {
            case 1:
                name = "咖啡";
                break;
            case 2:
                name = "矿泉水";
                break;
            case 3:
                name = "可乐";
                break;
            default:
                throw new IllegalArgumentException("参数不和法");
        }
        String ingredients = isCheckIngredients();
        double capacity = getCapacity();
        return setDrinkInfo(name, capacity, ingredients);


    }

    /**
     *  创建 Drink 对象
     * @param name
     * @param capacity
     * @param ingredients
     * @return
     */
    public static Drink setDrinkInfo(String name, double capacity, String ingredients) {
        Drink drink = null;
        switch (name) {
            case "咖啡":
                drink = new CoffeeDrink(name,capacity,ingredients);

            case "矿泉水":

                drink = new MineralDrink(name,capacity,ingredients);
            case "可乐":

                drink = new CokeDrink(name,capacity,ingredients);
                break;
            default:
                throw new IllegalStateException("Unexpected value: " + name);
        }

        return drink;
    }

    /**
     * 检查是否需要 添加配料
     */
    public static String isCheckIngredients() {
        Scanner in = new Scanner(System.in);
        System.out.println("请问是否要配料（1、加糖 2、加奶 3、什么也不加）");
        int choice = in.nextInt();
        String mixture;
        switch (choice) {
            case 1:
                mixture = "加糖";
                break;
            case 2:
                mixture = "加奶";
                break;
            default:
                mixture = "什么一个不加";
        }
        return mixture;
    }

    /**
     * 获得容量
     *
     * @return
     */
    public static double getCapacity() {
        Scanner in = new Scanner(System.in);
        System.out.println("请输入购买容量：");
        return in.nextInt();
    }
}
